#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>

typedef struct Stack
{
	char* a;
	int capacity;
	int top;
}Stack;



void StackInit(Stack* ps)
{

	ps->a = (char*)malloc(sizeof(char) * 4);
	ps->top = 0;
	ps->capacity = 4;
}

void StackPush(Stack* ps, int e)
{
	assert(ps);
	if (ps->capacity == ps->top)
	{
		int newcapacity = 2 * ps->capacity;
		char* temp = realloc(ps->a, sizeof(char) * newcapacity);
		if (temp == NULL)
		{
			printf("realloc fail\n");
			exit(-1);
		}
		else
		{
			ps->capacity = newcapacity;
			ps->a = temp;
		}
	}
	ps->a[ps->top] = e;
	ps->top++;
}

void  StackPop(Stack* ps)
{
	ps->top--;
}

int StackIsEmpty(Stack* ps)
{
	return ps->top == 0;
}


char StackTop(Stack* ps)
{
	assert(!StackIsEmpty(ps));
	return ps->a[ps->top - 1];
}



void StackDestory(Stack* ps)
{
	free(ps->a);
	ps->a = NULL;
	ps->top = ps->capacity = 0;
}


int main()
{

	char str[] = "{}()[(]";
	
	Stack ST;
	StackInit(&ST);
	char* s = str;
	while (*s)
	{
		if (( * s == '(' )||( * s == '{') ||( * s == '['))
		{
			StackPush(&ST,*s);
			s++;
		}
		else
		{
			if (StackIsEmpty(&ST))
			{
				
				StackDestory(&ST);
				printf("NO\n");
				return 0;
			}
			char ch = StackTop(&ST);
			if(( * s == ')' && ch != '(')||( * s == ']' && ch != '[')||(* s == '}' && ch != '{'))
			{
				
				StackDestory(&ST);
				printf("NO\n");
				return 0;
			}
			else
			{
				StackPop(&ST);
				s++;
			}
		}
	}
	if (StackIsEmpty(&ST))
	{
		printf("YRS\n");
	}
	else
	{
		printf("NO\n");
	}

	StackDestory(&ST);
	return 0;


}
